User can now change password without having to provide an invitation code

itkevin 12 years ago
parent
commit
2a9c5e172a
4 changed files with 21 additions and 9 deletions
  1. 1 0
      Gemfile
  2. 9 0
      Gemfile.lock
  3. 1 1
      app/models/user.rb
  4. 10 8
      spec/models/users_spec.rb

+ 1 - 0
Gemfile

@@ -48,6 +48,7 @@ end
48 48
 group :development, :test do
49 49
   gem 'rspec-rails'
50 50
   gem 'rspec'
51
+  gem 'shoulda-matchers'
51 52
   gem 'rr'
52 53
   gem 'webmock', :require => false
53 54
   gem 'rake'

+ 9 - 0
Gemfile.lock

@@ -43,6 +43,8 @@ GEM
43 43
       rails (>= 3.1)
44 44
     bootstrap-sass (2.3.0.1)
45 45
       sass (~> 3.2)
46
+    bourne (1.4.0)
47
+      mocha (~> 0.13.2)
46 48
     builder (3.0.4)
47 49
     coderay (1.0.9)
48 50
     coffee-rails (3.2.2)
@@ -119,8 +121,11 @@ GEM
119 121
       i18n (>= 0.4.0)
120 122
       mime-types (~> 1.16)
121 123
       treetop (~> 1.4.8)
124
+    metaclass (0.0.1)
122 125
     method_source (0.8.1)
123 126
     mime-types (1.21)
127
+    mocha (0.13.3)
128
+      metaclass (~> 0.0.1)
124 129
     multi_json (1.6.1)
125 130
     multi_xml (0.5.3)
126 131
     multipart-post (1.2.0)
@@ -204,6 +209,9 @@ GEM
204 209
     select2-rails (3.3.1)
205 210
       sass-rails (>= 3.2)
206 211
       thor (~> 0.14)
212
+    shoulda-matchers (1.5.6)
213
+      activesupport (>= 3.0.0)
214
+      bourne (~> 1.3)
207 215
     simple_oauth (0.1.9)
208 216
     slop (3.4.3)
209 217
     sprockets (2.2.2)
@@ -273,6 +281,7 @@ DEPENDENCIES
273 281
   safe_yaml (= 0.8.6)
274 282
   sass-rails (~> 3.2.3)
275 283
   select2-rails
284
+  shoulda-matchers
276 285
   system_timer
277 286
   twitter
278 287
   twitter-stream (>= 0.1.16)

+ 1 - 1
app/models/user.rb

@@ -19,7 +19,7 @@ class User < ActiveRecord::Base
19 19
   validates_presence_of :username
20 20
   validates_uniqueness_of :username
21 21
   validates_format_of :username, :with => /\A[a-zA-Z0-9_-]{3,15}\Z/, :message => "can only contain letters, numbers, underscores, and dashes, and must be between 3 and 15 characters in length."
22
-  validates_inclusion_of :invitation_code, :in => INVITATION_CODES, :message => "is not valid"
22
+  validates_inclusion_of :invitation_code, :on => :create, :in => INVITATION_CODES, :message => "is not valid"
23 23
 
24 24
   has_many :events, :order => "events.created_at desc", :dependent => :delete_all, :inverse_of => :user
25 25
   has_many :agents, :order => "agents.created_at desc", :dependent => :destroy, :inverse_of => :user

+ 10 - 8
spec/models/users_spec.rb

@@ -3,14 +3,16 @@ require 'spec_helper'
3 3
 describe User do
4 4
   describe "validations" do
5 5
     describe "invitation_code" do
6
-      it "should be required and only be valid when set to one of the allowed values" do
7
-        users(:bob).should be_valid
8
-        users(:bob).invitation_code = ""
9
-        users(:bob).should_not be_valid
10
-        users(:bob).invitation_code = "something_fake"
11
-        users(:bob).should_not be_valid
12
-        users(:bob).invitation_code = User::INVITATION_CODES.first
13
-        users(:bob).should be_valid
6
+      it "only accepts valid invitation codes" do
7
+      	User::INVITATION_CODES.each do |v|
8
+    			should allow_value(v).for(:invitation_code)
9
+  			end
10
+      end
11
+
12
+      it "can reject invalid invitation codes" do
13
+      	%w['foo', 'bar'].each do |v|
14
+    			should_not allow_value(v).for(:invitation_code)
15
+  			end
14 16
       end
15 17
     end
16 18
   end